class AddTestData < ActiveRecord::Migration
  def self.up
    #cleans the database
    down
  
    #creating relationship types
    RelationshipType.create(:name => "provided by")
    RelationshipType.create(:name => "hosted by")
    RelationshipType.create(:name => "depends on")

    #creating configuration items and relationships
    c1 = Ci.create (:name => "website", :status => 0)
    c2 = Ci.create (:name => "server22", :status => 0)
    c3 = Ci.create (:name => "apache_server22", :status => 0)
    c4 = Ci.create (:name => "jetty_server22", :status => 0)
    c1.relationships << Relationship.new (:source_ci => c1, :destination_ci => c3, :relationship_type => RelationshipType.find_by_name(RelationshipType::PROVIDED_BY))
    c4.relationships << Relationship.new (:source_ci => c4, :destination_ci => c2, :relationship_type => RelationshipType.find_by_name(RelationshipType::HOSTED_BY))
    c3.relationships << Relationship.new (:source_ci => c3, :destination_ci => c4, :relationship_type => RelationshipType.find_by_name(RelationshipType::DEPENDS_ON))
    c3.relationships << Relationship.new (:source_ci => c3, :destination_ci => c2, :relationship_type => RelationshipType.find_by_name(RelationshipType::HOSTED_BY))
  end

  def self.down
    #cleans the database
    Relationship.delete_all
    Ci.delete_all
    RelationshipType.delete_all
  end
end

 
